import os

from langchain.agents import AgentType
from langchain.agents import load_tools, initialize_agent
from langchain_community.llms.baidu_qianfan_endpoint import QianfanLLMEndpoint

os.environ["QIANFAN_AK"] = "ZGgmCMM95MfabqYLG2swwRWM"
os.environ["QIANFAN_SK"] = "yDAIOpvEu7vm2phjYDT5sdIg5h4LBb4v"

llm = QianfanLLMEndpoint(streaming=True)
# 加载工具
tools = load_tools(["llm-math", "wikipedia"], llm=llm)
agent_executor = initialize_agent(
    tools,
    llm,
    agent=AgentType.CHAT_ZERO_SHOT_REACT_DESCRIPTION,
    handle_parsing_errors=True,
    verbose=True)
result = agent_executor("What is the 25% of 300?")
print("运行结果：")
print(result['output'])
